package design_pattern.WorkerThreadMode;

import java.util.Random;

/**
 * @Author: 蔡翔
 * @Date: 2019/11/19 15:37
 * @Version 1.0
 */
public class WorkThread extends Thread {
    private final Channel channel;
    private final static Random random = new Random();

    public WorkThread(String name, Channel channel) {
        super(name);
        this.channel = channel;
    }

    @Override
    public void run() {
        while (true){
            channel.take().execute();
            try {
                //默认这个线程花费的时间。
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
